# TODO 导入pymysql
import pymysql
# TODO 通过用户名或年龄获取用户信息
# TODO 创建连接对象和游标对象
conn = pymysql.connect(user='root', password='root', database='advanced', charset='utf8')
cursor = conn.cursor()
# TODO 执行sql语句
name = input('请输入姓名:')
age = int(input('年龄:'))
sql = "select * from student where stu_name = %s or stu_age = %s"            # 注意:sql注入解决的占位符,不能使用引号包裹
print(sql)
rul = cursor.execute(sql, [name, age])
if rul:
    #  获取结果集
    student = cursor.fetchall()
    print(student)
else:
    print('没有这个学生信息')
# TODO 关闭资源
cursor.close()
conn.close()